<div data-dux="table-bind">
    <div class="dux-page-header uk-clearfix">
        <div class="page-title">
            <a class="uk-button uk-button-primary" href="javascript:;" id="update"> 上传菜单</a>
        </div>
        <div class="page-action">
            <a class="uk-button uk-button-primary" href="{url('add')}">添加</a>
        </div>
    </div>
    <div class="dux-page-table">
        <table class="uk-table  uk-table-responsive  uk-table-striped uk-table-hover uk-table-middle dux-table" data-table>
            <thead>
            <tr>
                <th>菜单名称</th>
                <th>菜单类型</th>
                <th>触发内容</th>
                <th class="uk-text-center" width="120">管理</th>
            </tr>
            </thead>
            <tbody>
            <!--loop{$list as $vo}-->
            <tr>
                <td>{$vo.cname}</td>
                <td>
                    {$vo.type ? '关键词' : '跳转'}
                </td>
                <td class="uk-text-break">{str_len($vo.key, 50)}</td>
                <td class="uk-text-center">
                    <a class="uk-button uk-button-primary uk-button-small" href="{url('edit', ['id'=>$vo[$pri]])}" title="编辑"><i class="fa fa-pencil"></i></a>
                    <a class="uk-button uk-button-danger uk-button-small" href="javascript:;" data-url="{url('del')}" data-id="{$vo[$pri]}" title="删除" data-del><i class=" fa fa-trash"></i></a>
                </td>
            </tr>
            <!--{/loop}-->
            </tbody>
        </table>
    </div>
    <div class="dux-page-foot uk-clearfix">
        {$page}
    </div>
</div>

<script>
    Do('base', 'dialog', function () {
        var dialog = null;
        var sync = function (pageNum) {
            app.debug(pageNum);
            app.ajax({
                url: '{url("sync")}',
                type: 'post',
                data: {
                    page: pageNum
                },
                tip: false,
                success: function (info) {
                    dialog.msg('素材完成页数(' + info.num + '/' + info.max + ')', 200);
                    sync(pageNum + 1);
                },
                error : function(msg, url) {
                    dialog.close();
                    dialog.msg(msg);
                    if(url) {
                        setTimeout(function() {
                            window.location.href = url;
                        }, 2000);
                    }
                }
            });

        };

        $('#update').click(function () {
            dialog.confirm({
                title : '上传菜单将删除现有菜单,请确认？',
                callback : [
                    function(index) {
                        dialog.msg('上传中,请稍等!', 200);
                        app.ajax({
                            url: '{url("updateMenu")}',
                            type: 'post',
                            data: {},
                            tip: false,
                            success: function (msg) {
                                dialog.close();
                                dialog.msg(msg);
                            },
                            error: function (msg, url) {
                                dialog.close();
                                dialog.msg(msg);
                            }
                        });
                    }
                ]
            });

        });

    });
</script>